﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="update.aspx.cs" Inherits="HungryCrowd.trader.update" MasterPageFile="~/master/Main.Master" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <div class="formLayout">
        <asp:Label ID="lblHeader" runat="server" ClientIDMode="Static" Text="Create a Trader"></asp:Label>
        <div class="col1" style="">
            <div style="float:left;">Name: </div>
            <div class="elementAlign">
                <asp:TextBox ID="txtName" runat="server" ClientIDMode="Static"></asp:TextBox></div>
        </div>
        <div class="col1">
            <div style="float:left;">Contact Person: </div>
            <div class="elementAlign">
                <asp:TextBox ID="txtContactPerson" runat="server" ClientIDMode="Static"></asp:TextBox></div>
        </div>
        <div class="col1">
            <div style="float:left;">Contact Number: </div>
            <div class="elementAlign">
                <asp:TextBox ID="txtNumber" runat="server" ClientIDMode="Static"></asp:TextBox></div>
        </div>
        <div class="col1">
            <div style="float:left;">Trading Days: </div>
            <div class="elementAlign">
                <asp:TextBox ID="txtTradingDays" runat="server" ClientIDMode="Static"></asp:TextBox></div>
        </div>
        <div class="col1">
            <div style="float:left;">Trading Area: </div>
            <div class="elementAlign">
                <asp:TextBox ID="txtArea" runat="server" ClientIDMode="Static" Enabled="false"></asp:TextBox></div>
        </div>
        <div class="col1">
            <div style="float:left;">Trading Years: </div>
            <div class="elementAlign">
                <asp:TextBox ID="txtYears" runat="server" ClientIDMode="Static"></asp:TextBox></div>
        </div>
        <div class="col1">
            <div style="float:left;">Trading Hours: </div>
            <div class="elementAlign">
                <asp:TextBox ID="txtHours" runat="server" ClientIDMode="Static"></asp:TextBox></div>
        </div>
        <div class="col1">
            <div style="float:left;">Email Address: </div>
            <div class="elementAlign">
                <asp:TextBox ID="txtEmail" runat="server" ClientIDMode="Static"></asp:TextBox></div>
        </div>
        <div class="col1">
            <div style="float:left;">Website: </div>
            <div class="elementAlign">
                <asp:TextBox ID="txtWebsite" runat="server" ClientIDMode="Static"></asp:TextBox></div>
        </div>
        <div class="col1">
            <div style="float:left;">About: </div>
            <div class="elementAlign">
                <asp:TextBox ID="txtDescription" runat="server" ClientIDMode="Static"></asp:TextBox></div>
        </div>
        <div class="col1">
            <div style="float:left;">Profile Pic: </div>
            <div class="elementAlign">
                <asp:FileUpload ID="fluProfilePic" runat="server" ClientIDMode="Static"></asp:FileUpload></div>
        </div>
        <div class="col1">
            <div style="float:left;">Location:</div>
            <div class="elementAlign">
                <asp:DropDownList ID="ddlLocation" runat="server" ClientIDMode="Static" Width="155"></asp:DropDownList></div>
        </div>
        <div class="col1">
            <div style="float:left;">Markets:</div>
            <div class="elementAlign">
                <asp:DropDownList ID="ddlMarkets" runat="server" ClientIDMode="Static" Width="155"></asp:DropDownList>
            </div>
        </div>
         <div class="col1">
            <div style="float:left;">Category:</div>  
            <div class="elementAlign">
                <asp:DropDownList ID="ddlCategories" runat="server" ClientIDMode="Static" Width="155"></asp:DropDownList>
            </div>
        </div>
        <div style="width: 100%; float: left; margin-left: auto; margin-right: auto;">
            <asp:Button ID="btnSubmit" Text="Create" runat="server" Width="80px" ClientIDMode="Static" OnClick="btnSubmit_Click" />
            <input type="button" id="save" onclick="saveTrader();" value="Save" />
        </div> 
        <asp:HiddenField ID="hdArea" ClientIDMode="Static" runat="server" />
        <asp:HiddenField ID="hdMarketId" ClientIDMode="Static" runat="server" />
        <asp:HiddenField ID="hdCategoryId" ClientIDMode="Static" runat="server" />
        <asp:HiddenField ID="hdHiddenField" ClientIDMode="Static" runat="server" />
    </div>
    <script type="text/javascript">
        $('#ddlMarkets').change(function () {            
            var selectedId = $('#ddlMarkets option:selected').val();
            var selectedText = $('#ddlMarkets option:selected').text();
            $('#hdMarketId').val(selectedId);
            $('#txtArea').val(selectedText);
        });

        $('#ddlCategories').change(function () {
            var selectedId = $('#ddlCategories option:selected').val();
            $('#hdCategoryId').val(selectedId);
        });

        $('#ddlLocation').change(function () {
            var selected = $('#ddlLocation option:selected').text();
            $('#hdArea').val(selected);
        });

        function saveTrader() {
            var obj = $('#hdHiddenField').val();
            var jsonObj = JSON.parse(obj);
            var dataToSend = { Trader: JSON.stringify(jsonObj), MethodName: 'SaveTrader' };

            var options = {
                data: dataToSend,
                dataType: 'JSON',
                type: 'POST',
                url: '/server/ajax.aspx',
                success: function (response, status, XHR) {
                    if (status != 'success') {
                        debugger;
                        alert('Error occurred.' + XHR);
                    }
                    else {
                        debugger;

                        if (response.toLowerCase() == "true")
                        {
                            $('.client').find("input[type=text], textarea").val("");
                            alert('success');
                            
                        }
                    }
                }
            };
            $.ajax(options);
        }
    </script>
</asp:Content>
